package bsi.vn.Data;

import java.util.ArrayList;

import android.content.Context;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import bsi.vn.FirstApp.R;

public class ErrorDetailAdapter extends BaseAdapter{
	private static ArrayList<ErrorDetailData> searchArrayList;
	private LayoutInflater mInflater;
	
	public ErrorDetailAdapter(Context context, ArrayList<ErrorDetailData> results) {
		  searchArrayList = results;
		  mInflater = LayoutInflater.from(context);
	}

	public ErrorDetailAdapter(TextWatcher textWatcher, ArrayList<ErrorDetailData> results) {
		// TODO Auto-generated constructor stub
		searchArrayList = results;
		mInflater = LayoutInflater.from((Context) textWatcher);
	}

	@Override
	public int getCount() {
		  return searchArrayList.size();
	}

	@Override
	public Object getItem(int position) {
		  return searchArrayList.get(position);
	}

	@Override
	public long getItemId(int position) {
		  return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
		   convertView = mInflater.inflate(R.layout.errordetail_row, null);
		   holder = new ViewHolder();
		   holder.tvErrorDetailId = (TextView) convertView.findViewById(R.id.edtvErrorDetailId);
		   holder.tvOrder = (TextView) convertView.findViewById(R.id.edtvOrder);
		   holder.tvDescription = (TextView) convertView.findViewById(R.id.edtvDescription);
		   
		   convertView.setTag(holder);
		} 
		else {
		   holder = (ViewHolder) convertView.getTag();
		}
		
		holder.tvErrorDetailId.setText(String.valueOf(searchArrayList.get(position).getErrorDetailId()));
		holder.tvDescription.setText(searchArrayList.get(position).getDescription());
		holder.tvOrder.setText(String.valueOf(searchArrayList.get(position).getOrder()));
		
		return convertView;
	}
	
	static class ViewHolder {
		  TextView tvErrorDetailId;
		  TextView tvOrder;
		  TextView tvDescription;
	}
}
